package com.cssw.fyzb.busi.api.live;

import com.cssw.fyzb.core.model.vo.live.LiveKickOutVo;
import com.cssw.fyzb.busi.service.live.LiveService;
import com.cssw.fyzb.busi.service.user.UserService;
import com.cssw.fyzb.core.model.dodb.CmfLiveKickOut;
import com.cssw.fyzb.core.model.mos.UserMo;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import com.ydn.dbframe.plugin.activerecord.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 获取踢出列表
 * @author wondream
 */
@Function(description = "获取踢出列表", parameters = {
        @Parameter(name = "liveId", type = Type.String, description = "用户标识", required = true),
        @Parameter(name = "pageNumber", type = Type.String, description = "当前页，从1开始", required = true),
        @Parameter(name = "pageSize", type = Type.String, description = "页大小", required = true)
})
@Component
public class ListLiveKickOut implements Action {

    @Autowired
    LiveService liveService;

    @Autowired
    UserService userService;

    @Override
    public Response execute(Request request) throws Exception {
        Long liveId = request.getLong("liveId");
        Integer pageNumber = request.getInteger("pageNumber");
        Integer pageSize = request.getInteger("pageSize");
        Page<CmfLiveKickOut> page = liveService.listLiveKickOut(liveId, pageNumber, pageSize);
        List<LiveKickOutVo> vos = new ArrayList<>();
        LiveKickOutVo vo = null;
        for (CmfLiveKickOut c : page.getList()) {
            vo = new LiveKickOutVo();
            vo.setUserId(c.getUserId());
            vo.setKoId(c.getKoId());
            vo.setLiveId(c.getLiveId());

            UserMo userMo = userService.findById(c.getUserId());
            if (null != userMo){
                vo.setAvatar(userMo.getAvatar());
                vo.setNickName(userMo.getNickName());
            }
            vos.add(vo);
        }
        return Response.success().put("list", vos).put("total", page.getTotalPage()).put("count", page.getTotalRow());
    }
}
